using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SysFrame.Message;
using System.Reflection;
using System.Data;
using MySql.Data.MySqlClient;

namespace SysFrame.BP
{
    /// <summary>
    /// system_1方法
    /// </summary>
    public class MySQLsystem_1: Isystem_1
    {

        /// <summary>
        /// 得到system_1实体
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public List<Mssystem_1> Getsystem_1MsByQuery(MsQuery msq)
        {
            List<Mssystem_1> listms=new List<Mssystem_1>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select system_1.* ");
            sb.Append(" from system_1 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder != null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                DataSet ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
               if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
                {
                	foreach(DataRow dr in ds.Tables[0].Rows)
                	{
                    	Mssystem_1 ms = new Mssystem_1();
                    	if(dr["System_1_10"].ToString()!=""){ms.System_1_10=int.Parse(dr["System_1_10"].ToString());}
                    	if(dr["System_1_20"]!=null){ms.System_1_20=dr["System_1_20"].ToString();}
                    	if(dr["System_1_30"]!=null){ms.System_1_30=dr["System_1_30"].ToString();}
                    	if(dr["System_1_40"]!=null){ms.System_1_40=dr["System_1_40"].ToString();}
                    	if(dr["System_1_50"]!=null){ms.System_1_50=dr["System_1_50"].ToString();}
                    	if(dr["System_1_60"]!=null){ms.System_1_60=dr["System_1_60"].ToString();}
                    	if(dr["System_1_70"]!=null){ms.System_1_70=dr["System_1_70"].ToString();}
                    	if(dr["System_1_80"]!=null){ms.System_1_80=dr["System_1_80"].ToString();}
                    	if(dr["System_1_90"]!=null){ms.System_1_90=dr["System_1_90"].ToString();}
                    	if(dr["System_1_100"]!=null){ms.System_1_100=dr["System_1_100"].ToString();}
                    	if(dr["System_1_110"]!=null){ms.System_1_110=dr["System_1_110"].ToString();}
                    	if(dr["System_1_120"]!=null){ms.System_1_120=dr["System_1_120"].ToString();}
                    	if(dr["System_1_130"]!=null){ms.System_1_130=dr["System_1_130"].ToString();}
                    	if(dr["System_1_140"]!=null){ms.System_1_140=dr["System_1_140"].ToString();}
                    	if(dr["System_1_150"]!=null){ms.System_1_150=dr["System_1_150"].ToString();}
                    	if(dr["System_1_160"]!=null){ms.System_1_160=dr["System_1_160"].ToString();}
                    	if(dr["System_1_170"]!=null){
                            ms.System_1_170=dr["System_1_170"].ToString();
                            ms.sys2 = new Mssystem_2();
                            try {
                                ms.sys2 = new BLLsystem_2().Getsystem_2MsByKey(ms.System_1_170);
                            } catch { }
                        }
                    	if(dr["System_1_180"]!=null){ms.System_1_180=dr["System_1_180"].ToString();}
                    	if(dr["System_1_190"]!=null){ms.System_1_190=dr["System_1_190"].ToString();}
                    	if(dr["System_1_200"]!=null){ms.System_1_200=dr["System_1_200"].ToString();}
                    	if(dr["System_1_210"]!=null){ms.System_1_210=dr["System_1_210"].ToString();}
                    	if(dr["System_1_220"]!=null){ms.System_1_220=dr["System_1_220"].ToString();}
                    	if(dr["System_1_230"]!=null){ms.System_1_230=dr["System_1_230"].ToString();}
                    	if(dr["System_1_9990"].ToString()!=""){ms.System_1_9990=DateTime.Parse(dr["System_1_9990"].ToString());}
                    	if(dr["System_1_9991"]!=null){ms.System_1_9991=dr["System_1_9991"].ToString();}
                    	if(dr["System_1_9992"]!=null){ms.System_1_9992=dr["System_1_9992"].ToString();}
                    	if(dr["System_1_9993"]!=null){ms.System_1_9993=dr["System_1_9993"].ToString();}
                    	if(dr["System_1_9994"]!=null){ms.System_1_9994=dr["System_1_9994"].ToString();}
                    	if(dr["System_1_9995"]!=null){ms.System_1_9995=dr["System_1_9995"].ToString();}
                    	listms.Add(ms);
                	}
                }
            }
            catch{}
            return listms;
        }

        /// <summary>
        ///  保存system_1信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_1_10进行判断有System_1_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Savesystem_1(Mssystem_1 ms)
        {
            MsReturned msr = new MsReturned();
            if(ms.System_1_10 !=null && ms.System_1_10.ToString() !="" && ms.System_1_10.ToString() != "0")
            {
            	msr = Upsystem_1(ms);
            }
            else
            {
            	msr = Addsystem_1(ms);
            }
            return msr;
        }

        /// <summary>
        ///  新增system_1信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_1_10进行判断有System_1_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Addsystem_1(Mssystem_1 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
            int newRateId = DataBase.GetMaxId("system_1", "System_1_10");
            sb.Append("insert into system_1 (");
            sb.Append("System_1_10,System_1_20,System_1_30,System_1_40,System_1_50,");
            sb.Append("System_1_60,System_1_70,System_1_80,System_1_90,System_1_100,");
            sb.Append("System_1_110,System_1_120,System_1_130,System_1_140,System_1_150,");
            sb.Append("System_1_160,System_1_170,System_1_180,System_1_190,System_1_200,");
            sb.Append("System_1_210,System_1_220,System_1_230,System_1_9990,System_1_9991,");
            sb.Append("System_1_9992,System_1_9993,System_1_9994,System_1_9995");
            sb.Append(")");
            sb.Append("values ( ");
            sb.Append(newRateId.ToString()).Append(",");
            sb.Append("@System_1_20,@System_1_30,@System_1_40,@System_1_50,");
            sb.Append("@System_1_60,@System_1_70,@System_1_80,@System_1_90,@System_1_100,");
            sb.Append("@System_1_110,@System_1_120,@System_1_130,@System_1_140,@System_1_150,");
            sb.Append("@System_1_160,@System_1_170,@System_1_180,@System_1_190,@System_1_200,");
            sb.Append("@System_1_210,@System_1_220,@System_1_230,@System_1_9990,@System_1_9991,");
            sb.Append("@System_1_9992,@System_1_9993,@System_1_9994,@System_1_9995)");
            MySqlParameter[] parameters = {
            		new MySqlParameter("@System_1_10", MySqlDbType.Int32,11),
            		new MySqlParameter("@System_1_20", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_30", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_40", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_50", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_60", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_70", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_80", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_90", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_100", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_110", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_120", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_130", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_140", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_150", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_160", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_170", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_180", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_190", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_200", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_210", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_220", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_230", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_1_9990", MySqlDbType.DateTime),
            		new MySqlParameter("@System_1_9991", MySqlDbType.VarChar,1000),
            		new MySqlParameter("@System_1_9992", MySqlDbType.VarChar,1000),
            		new MySqlParameter("@System_1_9993", MySqlDbType.VarChar,1000),
            		new MySqlParameter("@System_1_9994", MySqlDbType.VarChar,1000),
            		new MySqlParameter("@System_1_9995", MySqlDbType.VarChar,1000)};
            parameters[0].Value = ms.System_1_10;
            parameters[1].Value = ms.System_1_20;
            parameters[2].Value = ms.System_1_30;
            parameters[3].Value = ms.System_1_40;
            parameters[4].Value = ms.System_1_50;
            parameters[5].Value = ms.System_1_60;
            parameters[6].Value = ms.System_1_70;
            parameters[7].Value = ms.System_1_80;
            parameters[8].Value = ms.System_1_90;
            parameters[9].Value = ms.System_1_100;
            parameters[10].Value = ms.System_1_110;
            parameters[11].Value = ms.System_1_120;
            parameters[12].Value = ms.System_1_130;
            parameters[13].Value = ms.System_1_140;
            parameters[14].Value = ms.System_1_150;
            parameters[15].Value = ms.System_1_160;
            parameters[16].Value = ms.System_1_170;
            parameters[17].Value = ms.System_1_180;
            parameters[18].Value = ms.System_1_190;
            parameters[19].Value = ms.System_1_200;
            parameters[20].Value = ms.System_1_210;
            parameters[21].Value = ms.System_1_220;
            parameters[22].Value = ms.System_1_230;
            parameters[23].Value = ms.System_1_9990;
            parameters[24].Value = ms.System_1_9991;
            parameters[25].Value = ms.System_1_9992;
            parameters[26].Value = ms.System_1_9993;
            parameters[27].Value = ms.System_1_9994;
            parameters[28].Value = ms.System_1_9995;
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString(),parameters);
                if (iexe > 0)
                {
                    msr.strMsId = newRateId.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch(Exception ex)
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!"+ ex.Message + ex.StackTrace + ex.Source;
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        ///  更新system_1信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_1_10进行判断有System_1_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Upsystem_1(Mssystem_1 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
           	sb.Append("update system_1 set ");
           	sb.Append(" System_1_10='").Append(ms.System_1_10).Append("' ");// System_1_10 
           	if (ms.System_1_20 !=null && ms.System_1_20.ToString() != ""){
           	    sb.Append(",").Append(" System_1_20='").Append(ms.System_1_20).Append("' ");// System_1_20 
           	}
           	if (ms.System_1_30 !=null && ms.System_1_30.ToString() != ""){
           	    sb.Append(",").Append(" System_1_30='").Append(ms.System_1_30).Append("' ");// System_1_30 
           	}
           	if (ms.System_1_40 !=null && ms.System_1_40.ToString() != ""){
           	    sb.Append(",").Append(" System_1_40='").Append(ms.System_1_40).Append("' ");// System_1_40 
           	}
           	if (ms.System_1_50 !=null && ms.System_1_50.ToString() != ""){
           	    sb.Append(",").Append(" System_1_50='").Append(ms.System_1_50).Append("' ");// System_1_50 
           	}
           	if (ms.System_1_60 !=null && ms.System_1_60.ToString() != ""){
           	    sb.Append(",").Append(" System_1_60='").Append(ms.System_1_60).Append("' ");// System_1_60 
           	}
           	if (ms.System_1_70 !=null && ms.System_1_70.ToString() != ""){
           	    sb.Append(",").Append(" System_1_70='").Append(ms.System_1_70).Append("' ");// System_1_70 
           	}
           	if (ms.System_1_80 !=null && ms.System_1_80.ToString() != ""){
           	    sb.Append(",").Append(" System_1_80='").Append(ms.System_1_80).Append("' ");// System_1_80 
           	}
           	if (ms.System_1_90 !=null && ms.System_1_90.ToString() != ""){
           	    sb.Append(",").Append(" System_1_90='").Append(ms.System_1_90).Append("' ");// System_1_90 
           	}
           	if (ms.System_1_100 !=null && ms.System_1_100.ToString() != ""){
           	    sb.Append(",").Append(" System_1_100='").Append(ms.System_1_100).Append("' ");// System_1_100 
           	}
           	if (ms.System_1_110 !=null && ms.System_1_110.ToString() != ""){
           	    sb.Append(",").Append(" System_1_110='").Append(ms.System_1_110).Append("' ");// System_1_110 
           	}
           	if (ms.System_1_120 !=null && ms.System_1_120.ToString() != ""){
           	    sb.Append(",").Append(" System_1_120='").Append(ms.System_1_120).Append("' ");// System_1_120 
           	}
           	if (ms.System_1_130 !=null && ms.System_1_130.ToString() != ""){
           	    sb.Append(",").Append(" System_1_130='").Append(ms.System_1_130).Append("' ");// System_1_130 
           	}
           	if (ms.System_1_140 !=null && ms.System_1_140.ToString() != ""){
           	    sb.Append(",").Append(" System_1_140='").Append(ms.System_1_140).Append("' ");// System_1_140 
           	}
           	if (ms.System_1_150 !=null && ms.System_1_150.ToString() != ""){
           	    sb.Append(",").Append(" System_1_150='").Append(ms.System_1_150).Append("' ");// System_1_150 
           	}
           	if (ms.System_1_160 !=null && ms.System_1_160.ToString() != ""){
           	    sb.Append(",").Append(" System_1_160='").Append(ms.System_1_160).Append("' ");// System_1_160 
           	}
           	if (ms.System_1_170 !=null && ms.System_1_170.ToString() != ""){
           	    sb.Append(",").Append(" System_1_170='").Append(ms.System_1_170).Append("' ");// System_1_170 
           	}
           	if (ms.System_1_180 !=null && ms.System_1_180.ToString() != ""){
           	    sb.Append(",").Append(" System_1_180='").Append(ms.System_1_180).Append("' ");// System_1_180 
           	}
           	if (ms.System_1_190 !=null && ms.System_1_190.ToString() != ""){
           	    sb.Append(",").Append(" System_1_190='").Append(ms.System_1_190).Append("' ");// System_1_190 
           	}
           	if (ms.System_1_200 !=null && ms.System_1_200.ToString() != ""){
           	    sb.Append(",").Append(" System_1_200='").Append(ms.System_1_200).Append("' ");// System_1_200 
           	}
           	if (ms.System_1_210 !=null && ms.System_1_210.ToString() != ""){
           	    sb.Append(",").Append(" System_1_210='").Append(ms.System_1_210).Append("' ");// System_1_210 
           	}
           	if (ms.System_1_220 !=null && ms.System_1_220.ToString() != ""){
           	    sb.Append(",").Append(" System_1_220='").Append(ms.System_1_220).Append("' ");// System_1_220 
           	}
           	if (ms.System_1_230 !=null && ms.System_1_230.ToString() != ""){
           	    sb.Append(",").Append(" System_1_230='").Append(ms.System_1_230).Append("' ");// System_1_230 
           	}
           	if (ms.System_1_9990 !=null && ms.System_1_9990.ToString() != "" && ms.System_1_9990.ToString().IndexOf("01-1-1")<0){
           	    sb.Append(",").Append(" System_1_9990='").Append(ms.System_1_9990).Append("' ");// System_1_9990 
           	}
           	if (ms.System_1_9991 !=null && ms.System_1_9991.ToString() != ""){
           	    sb.Append(",").Append(" System_1_9991='").Append(ms.System_1_9991).Append("' ");// System_1_9991 
           	}
           	if (ms.System_1_9992 !=null && ms.System_1_9992.ToString() != ""){
           	    sb.Append(",").Append(" System_1_9992='").Append(ms.System_1_9992).Append("' ");// System_1_9992 
           	}
           	if (ms.System_1_9993 !=null && ms.System_1_9993.ToString() != ""){
           	    sb.Append(",").Append(" System_1_9993='").Append(ms.System_1_9993).Append("' ");// System_1_9993 
           	}
           	if (ms.System_1_9994 !=null && ms.System_1_9994.ToString() != ""){
           	    sb.Append(",").Append(" System_1_9994='").Append(ms.System_1_9994).Append("' ");// System_1_9994 
           	}
           	if (ms.System_1_9995 !=null && ms.System_1_9995.ToString() != ""){
           	    sb.Append(",").Append(" System_1_9995='").Append(ms.System_1_9995).Append("' ");// System_1_9995 
           	}
           	sb.Append(" where System_1_10='").Append(ms.System_1_10).Append("'");// System_1_10 
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString());
                if (iexe > 0)
                {
                    msr.strMsId = ms.System_1_10.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch (Exception ex)
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!" + ex.Message + ex.StackTrace + ex.Source;
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        /// 得到数据类型
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns>数据类型</returns>
        public MsReturned Getsystem_1ByQuery(MsQuery msq)
        {
        	DataSet ds = null;
        	MsReturned msr = new MsReturned();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select system_1.* ");
            sb.Append(" from system_1 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder!=null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
            }
            catch{}
            msr.data = ds;
            return msr;
        }

        /// <summary>
        /// 删除system_1
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deletesystem_1ByQuery(MsQuery msq)
        {
            StringBuilder sb = new StringBuilder();
            MsReturned msr = new MsReturned();
            sb.Append(" delete from system_1 where System_1_10 > 0 ").Append(msq.strquery);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(sb.ToString());
                if (iexe > 0)
                {
                    msr.strMsId = "1";
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            sb = null;
            return msr;
        }

    }
}
